use anyhow::Ok;
use common::db;

pub async fn init() -> anyhow::Result<()> {
    dotenvy::dotenv()?;
    init_log();
    db::init_db().await?;
    Ok(())
}

fn init_log() {
    use time::{format_description, UtcOffset};
    use tracing_subscriber::{fmt::time::OffsetTime, EnvFilter};
    let format = "[year]-[month]-[day] [hour]:[minute]:[second].[subsecond digits:3]";
    // 初始化日志
    tracing_subscriber::fmt()
        .with_env_filter(EnvFilter::from_default_env())
        .with_timer(OffsetTime::new(
            UtcOffset::current_local_offset().unwrap(),
            format_description::parse(format).unwrap(),
        ))
        .init();
    tracing::info!("日志初始化完成！")
}
